package com.t.e.leaksdemo;


import android.app.Application;
import android.content.Context;

import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

public class LeaksDemoApp extends Application {

    private RefWatcher refWatcher;

    public static RefWatcher getRefWatcher(Context context) {
        LeaksDemoApp application = (LeaksDemoApp) context.getApplicationContext();
        return application.refWatcher;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        refWatcher = LeakCanary.install(this);
    }

//    protected RefWatcher installLeakCanary() {
//        if (LeakCanary.isInAnalyzerProcess(this)) {
//            return RefWatcher.DISABLED;
//        } else {
//            ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults().build();
//            LeakCanary.enableDisplayLeakActivity(this);
//            ServiceHeapDumpListener heapDumpListener = new ServiceHeapDumpListener(this, DisplayLeakService.class);
//            final RefWatcher refWatcher = LeakCanary.androidWatcher(this, heapDumpListener, excludedRefs);
//            registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
//                @Override
//                public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
//
//                }
//
//                @Override
//                public void onActivityStarted(Activity activity) {
//
//                }
//
//                @Override
//                public void onActivityResumed(Activity activity) {
//
//                }
//
//                @Override
//                public void onActivityPaused(Activity activity) {
//
//                }
//
//                @Override
//                public void onActivityStopped(Activity activity) {
//
//                }
//
//                @Override
//                public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
//
//                }
//
//                public void onActivityDestroyed(Activity activity) {
//                    //if (activity instanceof ThirdPartyActivity) {//todo 这是原文
//                    /*if (activity instanceof MainActivity) {//不想查的activity
//                        return;
//                    }*/
//                    refWatcher.watch(activity);
//                }
//                // ...
//            });
//            return refWatcher;
//        }
//    }
}
